﻿namespace MVC注册中间件示例
{
    // 1. 定义中间件类（实现IMiddleware）
    public class TimingMiddleware : IMiddleware
    {
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var startTime = DateTime.Now;
            await next(context); // 传递请求给下一个中间件
            var endTime = DateTime.Now;
            var duration = endTime - startTime;
            context.Response.Headers.Add("X-Request-Duration", duration.TotalMilliseconds.ToString());
        }
    }
}
